<?php
class Website_model extends CI_Model
{
    private $table = 'website';
    
    public function total($getData)
    {   
        if($getData['type_page']){
           $this->db->where('type_page',$getData['type_page']);
        }
        return $this->db->count_all_results($this->table);
    }
    
    public function searchList($pageNum,$num,$getData)
    {
        if($getData['type_page']){
           $this->db->where('type_page',$getData['type_page']);
        }
        $this->db->order_by('sort','asc');
        $this->db->limit($pageNum,$num);
        $result =  $this->db->get($this->table);
        if($result->num_rows()>0){
        	return $result;
        }else{
        	return false;
        }
    }
    
    public function insertWebsite($postData)
    {
        $data = array(
            'list_name' => $postData['list_name'],
            'list_content' => $postData['list_content'],
            'type_page'    => $postData['type_page'],
            'sort'    => $postData['sort']
        );
        $this->db->insert($this->table, $data);
        return $this->db->insert_id();
    }
    
    public function updateWebsite($postData)
    {
        $data = array(
            'list_name' => $postData['list_name'],
            'list_content' => $postData['list_content'],
            'type_page'    => $postData['type_page'],
            'sort'    => $postData['sort']
        );
        $this->db->where('list_id', $postData['list_id']);
        return $this->db->update($this->table, $data);
    }
    
    public function findById($id)
    {
        $this->db->where('list_id',$id);
        return $this->db->get($this->table);
    }
    
    public function deleteByListId($id)
    {
        $this->db->where('list_id', $id);
        return $this->db->delete($this->table);
    }
}